package com.hxrd.androidprint;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.hxrd.androidprint.DBUtils.DBUtils;

public class UpdateUrlActivity extends AppCompatActivity {

    private RelativeLayout backLayout;
    private EditText etUrl;
    private Button btnCancel,btnSure;
    private String urlIp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update_url);

        backLayout= (RelativeLayout) findViewById(R.id.update_layout);
        etUrl= (EditText) findViewById(R.id.et_update_url);
        btnCancel= (Button) findViewById(R.id.btn_update_url_cancel);
        btnSure= (Button) findViewById(R.id.btn_update_url_sure);

        Intent intent=getIntent();
        urlIp=intent.getStringExtra("urlIp");


        initData();
    }

    private void initData() {
        etUrl.setText(urlIp);

        backLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


        btnSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                DBUtils.updateUrl(UpdateUrlActivity.this,urlIp,etUrl.getText().toString().trim());

                Toast.makeText(UpdateUrlActivity.this, "更改成功。", Toast.LENGTH_SHORT).show();

                finish();
            }
        });


        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }



}
